<template>
  <div class="comment">
    <!-- 提交评论 -->
    <div class="commit">
      <div class="commit-title">提交评论</div>
      <div class="commit-content">
        <van-field
          v-model="message"
          rows="2"
          autosize
          autofocus
          type="textarea"
          maxlength="50"
          placeholder="请输入留言"
          show-word-limit
        />
        <van-button type="info" @click="publishFn">发表</van-button>
      </div>
    </div>

    <!-- 评论列表 -->
    <div class="commit">
      <div class="commit-list">
        评论列表
        <span class="count">{{ total }}条评论</span>
      </div>
      <div class="commit-content" v-for="(item, index) in list" :key="index">
        <div class="connent">
          {{ item.content }}
        </div>
        <div class="user">
          <div class="name">{{ item.user_name }}</div>
          <div class="time">{{ item.add_time }}</div>
        </div>
      </div>
      <div class="button">
        <van-button plain type="danger" @click="loading">加载更多</van-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      message: "",
    };
  },
  props: {
    total: Number,
    list: Array,
  },
  methods: {
    loading() {
      this.$emit("loadingMore");
    },
    publishFn() {
      this.$emit("publishFn", this.message);
      this.message = "";
    },
  },
};
</script>

<style lang="less" scoped>
.button {
  padding: 0 10px;
  .van-button {
    border-radius: 5px;
  }
}
.connent {
  color: #a9a59d;
  margin: 10px 0;
  font-size: 15px;
}
.user {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #e3e3e5;
  .name {
    font-size: 15px;
    color: #3eaeff;
    margin-right: 170px;
  }
  .time {
    padding: 2px 0;
    font-size: 16px;
    color: #a9a59d;
  }
}
.commit-content {
  padding: 0 10px;
}
.commit-title {
  font-size: 25px;
  font-weight: bold;
  padding: 15px 10px;
  border-bottom: 1px solid #e3e3e5;
  border-top: 1px solid #e3e3e5;
  margin-top: 150px;
}
.van-field {
  margin-top: 10px;
  border: 1px solid #e3e3e5;
  border-radius: 5px;
}
.van-button {
  margin-top: 10px;
  width: 100%;
  margin: 10px 0;
}
.commit-list {
  font-size: 25px;
  font-weight: bold;
  padding: 15px 10px;
  border-top: 1px solid #e3e3e5;
  border-bottom: 1px solid #e3e3e5;
  .count {
    display: inline-block;
    font-size: 15px;
    margin-left: 150px;
  }
}
</style>
